<template>
  <div>
    <!-- 如何获取DOM -->
    <!-- 1.通过ref属性绑定要获取的DOM元素 -->
    <!-- <div ref="box">{{count}}</div>
    <button @click="getDom">press</button>
    <div ref="screen" class="screen">
      <div v-for="item in 100" :key="item">{{item}}</div> 
    </div> -->
    <!-- <input ref="ipt" type="text" v-if="isShow" /> -->
    <!-- <button @click="changeShow" v-else>搜索</button> -->
    <button @click="changeComponent">press</button>
    <component :is="componentState" />
  </div>
</template>

<script>
import ChildOne from "./components/ChildOne.vue";
import ChildTwo from "./components/ChildTwo.vue";
export default {
  components: { ChildOne, ChildTwo },
  data() {
    return {
      count: 0,
      isShow: false,
      componentState: "ChildOne",
    };
  },
  methods: {
    changeComponent() {
      this.componentState =
        this.componentState === "ChildOne" ? "ChildTwo" : "ChildOne";
    },
    changeShow() {
      this.isShow = true;
      this.$nextTick(() => {
        this.$refs.ipt.focus();
      });
    },
    getDom() {
      this.count++;
      // console.log(this.$refs.box.innerHTML);
      // setTimeout(()=>{
      //   console.log(this.$refs.box.innerHTML)
      // },0)
      this.$nextTick(() => {
        // 视图更新
        console.log(this.$refs.box.innerHTML);
      });
      // 2.获取DOM
      // console.log(this.$refs.box);
      //  console.log(this.$refs.screen);
    },
  },
};
</script>

<style lang='less' scoped>
.screen {
  width: 375px;
  height: 800px;
  border: 1px solid #ccc;
  overflow: hidden;
}
</style>